import { reqGetUserAddress, reqGetOrderInfo } from '@/api';

const state = {
    addressInfo: [],
    orderInfo: {},
};

const mutations = {
    GetUserAddress(state, addressInfo){
        state.addressInfo = addressInfo;
    },
    GetOrderInfo(state, orderInfo){
        state.orderInfo = orderInfo;
    },
}

const actions = {
    // 获取用户地址信息
    async getUserAddress({ commit }){
        let result = await reqGetUserAddress();
        console.log("getUserAddress", result);
        if(result.code == 200){
            commit("GetUserAddress", result.data);
            return "ok";
        }else{
            return Promise.reject(new Error('faile'));
        }
    },
    // 获取订单交易页信息
    async getOrderInfo({ commit }){
        let result = await reqGetOrderInfo();
        console.log("getOrderInfo", result);
        if(result.code == 200){
            commit("GetOrderInfo", result.data);
            return "ok";
        }else{
            return Promise.reject(new Error('faile'));
        }
    }
}

const getters = {
    
}

export default({
    state,
    mutations,
    actions,
    getters,
})


